package com.lagou.edu.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @author lyj
 * @Title: AutoDeliverController
 * @ProjectName lagou-parent
 * @Description: TODO
 * @date 2020/12/27 11:21
 */
@RestController
public class AutoDeliverController {
    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private DiscoveryClient discoveryClient;
    @GetMapping("/checkState/{userId}")
    public Integer findResumeOpenState(@PathVariable Long userId) {
//        Integer forObject =restTemplate.getForObject("http://localhost:8080/resume/openstate/" + userId,
//                        Integer.class);
//        System.out.println("======>>>调⽤简历微服务，获取到⽤户" + userId + "的默认简历当前状态为： " + forObject);


        List<ServiceInstance> serviceInstanceList = discoveryClient.getInstances("lagou-service-resume");
        ServiceInstance serviceInstance = serviceInstanceList.get(0);
        String host = serviceInstance.getHost();
        int port = serviceInstance.getPort();
        String url="http://"+host+":"+port+"/resume/openstate/"+userId;

        Integer forObject =restTemplate.getForObject(url,Integer.class);
        System.out.println("======>>>从eureka server获取服务提供者实例："+url);
        return forObject;
    }
}

